/**
* Copyright(C) 老纳慢走
*
*/
var addresses = new Array();
$(document).ready(function() {
request_customer_address("addresses_reserved");
//$("#seat_number").focus();
/* $("#contactPhone").blur(function(){
if (!isValidPhoneNumber(this.value)){
setInfoMsg("手机号码格式不对", true);
}
});*/
$("#address_reserved").click(function() {
var nextGo = $(this).next();
nextGo.animate({
height : 'toggle',
opacity : 'toggle',
duration : "slow"
}, function(){
if ($(this).css('display') == 'none'){
$("#address_reserved").addClass('xl-infor-f');
$("#address_reserved").removeClass('xl-infor-f-up');
}else{
$("#address_reserved").addClass('xl-infor-f-up');
$("#address_reserved").removeClass('xl-infor-f');
}
});
//return false;
});
$("#sceneform").submit(function(e){
var target = "apis/restaurant/scene";
var ajax_data = {
"rid": r_id,
"seat_number":$("#seat_number").val(),
"address_id":$("#address_id").val(),
"contactPerson":$("#contactPerson").val(),
"contactPhone":$("#contactPhone").val(),
"access_token":access_token
};
if (!checkSubmitInfo(ajax_data)) {
e.preventDefault();
}else{
if (ajax_data.address_id == "" || ajax_data.address_id == null) {
ajax_data.address_id = -1;
}
ajax_post_json(target, ajax_data, function(){
setInfoMsg("正在提交信息，请稍候...", false);
$("#nextButton").attr("disabled","true");
}, function(data){
if(data.result==true){
setTimeout("goMenu('"+$("#next_t").val() + "')",10);
}else if (data.result ==false && data.type == "msg"){
setInfoMsg(data.content, true);
$("#nextButton").removeAttr("disabled");
}else {
}
}, function(xhr, textStatus, errorThrown) {
setInfoMsg("系统繁忙，请稍后再试 ", true); //setInfoMsg(xhr.statusText);
$("#nextButton").removeAttr("disabled");
});
return false;
}
});
});
function checkSubmitInfo(data) {
if (data.seat_number.trim() == "") {
setInfoMsg("餐位序号不能为空", true);
return false;
} else if (data.contactPerson.trim() == "") {
setInfoMsg("客户姓名不能为空", true);
return false;
} else if (data.contactPhone.trim() == "") {
setInfoMsg("手机号码不能为空", true);
//$("#contactPhone").focus();
return false;
} else if (!isValidPhoneNumber(data.contactPhone)){
setInfoMsg("手机号码格式不对", true);
return false;
}
data.contactPerson = data.contactPerson.trim();
return true;
}
function goMenu(url){
window.location.href = url;
return false;
}
function choose_reserved_address(id, contact, phone){
$("#address_id").val(id);
$("#contactPerson").val(contact);
$("#contactPhone").val(phone);
}
function choose_address(id, contact, phone, address){
choose_reserved_address(id, contact, phone, address);
var input = $("#address_list").find("input:radio");
input.each(function(){
if (this.id == id){
this.checked = true;
}
});
}
function newAddress(id, contact, phone, address){
var addr = new Object();
addr.id = id;
addr.contact = contact;
addr.phone = phone;
addr.address=address;
return addr;
}
function m_beforeSend(){
};
function m_error(xhr, textStatus, errorThrown){
}
function request_customer_address(elementId){
ajax_post_json("apis/user/address", {
"user_id" : u_id,
"option" : "RETRIEVE_ALL",
"access_token":access_token
}, m_beforeSend, function(data) {
var pHtml = "";
var count = 0;
pHtml += "<div id=\"address_list\" style=\"padding-left: 0px; border-spacing:5px;\">";
$.each(data.content, function(index, item) {
// if (data.content.length == 1 || count == data.content.length-1)
// pHtml += "<div class=\"bottom-f\">";
// else
pHtml += "<div class=\"center-f\">";
pHtml += "<input type=\"radio\" id=\""+item.id+"\" name=\"addr_radio\" value=\"" + item.id + "\"> ";
pHtml += "<a href=\"javascript:choose_address('"+item.id+"','"+item.contactPerson+"','"+item.contactTel+"','"+(item.addressArea+" "+ item.contactAddress)+"')\"";
pHtml += "<span style=\"color:#333;\">" +item.contactPerson+"</span>";
pHtml += "<span style=\"color:#333; padding-left:18px;\">" +item.contactTel+"</span><br/>";
if ((item.addressArea +" " + item.contactAddress +"").length > 0){
pHtml += "<span style=\"color:#333; padding-left:18px;\">" +item.addressArea +" " + item.contactAddress+"</span>";
}
pHtml += "</a></div>";
addresses[index] = newAddress(item.id, item.contactPerson, item.contactTel, item.addressArea+" "+ item.contactAddress);
count++;
});
pHtml += "</div>";
$("#" + elementId).empty();
$("#" + elementId).append(pHtml);
var input = $("#address_list").find("input:radio");
input.each(function(){
if (this.id == $("#address_id").val()){
this.checked = true;
}
});
$("input[type=radio][name=addr_radio]").click(function() {
var cur_addr_id = this.id;
$.each(addresses, function(index, item){
if (item.id == cur_addr_id){
choose_reserved_address(item.id, item.contact, item.phone);
return false;
}
});
});
}, m_error);
}
function prompt_info_animate() {
$("#prompt_info_c").animate({
height : 'toggle',
opacity : 'toggle',
duration : "slow"
}, function(){
if ($("#prompt_info").hasClass("prompt_info_down")) {
$("#prompt_info").removeClass("prompt_info_down");
$("#prompt_info").addClass("prompt_info_up");
}else{
$("#prompt_info").removeClass("prompt_info_up");
$("#prompt_info").addClass("prompt_info_down");
}
});
}
function setInfoMsg(msg, disappear){
if (isValide(msg) && msg.length > 0) {
$("#info_msg").html(msg);
$("#info_msg_div").css({"display":"block", "height":"0px"});
$("#info_msg_div").animate({
height : '24px',
duration : "slow"
}, function(){});
}else {
$("#info_msg_div").animate({
height : '0px',
duration : 'slow'
}, function(){
$("#info_msg_div").css({"display":"none", "height":"0px"});
$("#info_msg").html(msg);
});
}
if (disappear){
setTimeout("setInfoMsg('', false)", 5000);
}
}